#!/bin/bash
#自动化安装k8s集群
# 传参检测
#定义变量
a=`tail -2 /etc/hosts | awk  '{print $2}'`
hosts=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|grep -v 172.17.0.1|awk '{print $2}'|tr -d "addr:"|head -1`



echo -e "\033[33m======================== 测试主机网络状态 =========================\033[0m"
for host in `echo "${hosts}"`
do
echo "============================${host} =========================="
ssh -o StrictHostKeyChecking=no ${USER}@${host} ping -c 3 www.baidu.com &>/dev/null
[ $? -eq 0 ] && echo  -e "\033[32m ${host} 网络正常\033[0m" ||echo  -e "\033[31m ${netnum}.${host} 网络异常\033[0m"
done

echo -e "\033[33m======================== check k8s status =========================\033[0m"
echo "-------------------------  k8s version list  ---------------------------"
kubectl version
echo
echo "-------------------------  All Healthy status check  -------------------"
kubectl get componentstatus
echo
echo "-------------------------  k8s cluster info list  ----------------------"
kubectl cluster-info
echo
echo "-------------------------  k8s all nodes list  -------------------------"
kubectl get nodes
echo "-------------------------  k8s all-namespaces's pods list   ------------"
kubectl get pod --all-namespaces
echo
echo "-------------------------  k8s all-namespaces's service network   ------"
kubectl get svc --all-namespaces
echo
echo "-------------------------  k8s welcome for you   -----------------------"





